<?php
define('HTTP_OK'                    ,200);
define('HTTP_CREATED'               ,201);
define('HTTP_BADREQUEST'            ,400);
define('HTTP_UNAUTHORIZED'          ,401);
define('HTTP_NOTFOUND'              ,404);
define('HTTP_CONFLICT'              ,409);
define('HTTP_INTERNALSERVERERROR'   ,500);
define('HTTP_NOTIMPLEMENTED'        ,501);

/**
 * Fonction permettant de retourner le header désiré
 * @param int $num : code http
 */
function HTTPStatus($num) {

   static $http = array (
       HTTP_OK                  => "HTTP/1.1 200 OK",
       HTTP_CREATED             => "HTTP/1.1 201 Created",
       HTTP_BADREQUEST          => "HTTP/1.1 400 Bad Request",
       HTTP_NOTFOUND            => "HTTP/1.1 404 Not Found",
       HTTP_CONFLICT            => "HTTP/1.1 409 Conflict",
       HTTP_INTERNALSERVERERROR => "HTTP/1.1 500 Internal Server Error",
       HTTP_NOTIMPLEMENTED      => "HTTP/1.1 501 Not Implemented",
   );

   if (!array_key_exists($num, $http)){
       $num = 500;
   }
   header($http[$num], TRUE, $num);
}
